package io.renren.modules.store.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.store.dao.TStoreFoodDao;
import io.renren.modules.store.entity.TStoreFoodEntity;
import io.renren.modules.store.service.TStoreFoodService;


@Service("tStoreFoodService")
public class TStoreFoodServiceImpl extends ServiceImpl<TStoreFoodDao, TStoreFoodEntity> implements TStoreFoodService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TStoreFoodEntity> page = this.page(
                new Query<TStoreFoodEntity>().getPage(params),
                new QueryWrapper<TStoreFoodEntity>()
                .eq(!params.get("sellerId").equals(""),"seller_id",params.get("sellerId"))
                .eq(!params.get("typeId").equals(""),"type_id",params.get("typeId"))
                        .eq(!params.get("key").equals(""),"food_name",params.get("key"))
                .or()
                        .eq(!params.get("key").equals(""),"short_code",params.get("key"))

        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryListFoodPage(Map<String, Object> params) {
        IPage<TStoreFoodEntity> page = this.page(
                new Query<TStoreFoodEntity>().getPage(params),
                new QueryWrapper<TStoreFoodEntity>()
                        .eq("status",1)
                        .eq(params.get("sellerId") != null,"seller_id",params.get("sellerId"))
                        .eq(Long.parseLong(params.get("typeId").toString())!=0,"type_id",params.get("typeId"))
                .like(params.get("useRange") != null,"use_range",params.get("useRange"))
        );

        return new PageUtils(page);
    }

}